package com.lz.yz.reward.web;

import com.github.pagehelper.PageHelper;
import com.lz.yz.base.entity.ReturnValue;
import com.lz.yz.member.entity.Feedback;
import com.lz.yz.order.enumeration.OrderType;
import com.lz.yz.reward.bean.ComplaintsBean;
import com.lz.yz.reward.dao.RewardMapper;
import com.lz.yz.reward.entity.Complaints;
import com.lz.yz.reward.entity.Reward;
import com.lz.yz.reward.enumeration.RewardStatus;
import com.lz.yz.reward.model.ComplaintsModel;
import com.lz.yz.reward.param.RewardParam;
import com.lz.yz.reward.service.ComplaintsService;
import com.util.common.Page;
import com.util.common.QueryList;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* Created by CodeGenerator on 2017/11/10.
*/

@RestController
@RequestMapping("/complaints")
public class ComplaintsController {

    private final Logger logger = LoggerFactory.getLogger(getClass());


    @Autowired
    private ComplaintsService complaintsService;

    @ApiOperation(value="查询投诉列表")
    @ApiImplicitParams({
    })
    @GetMapping("/queryComplaintsList")
    public ReturnValue list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {

        try {
            PageHelper.startPage(page, pageSize);
            List<ComplaintsBean> list = complaintsService.queryComplaintList();
            QueryList< ComplaintsBean> queryList = new QueryList(list, Page.toPage(list));
            return ReturnValue.generateTrueReturnValue(queryList);
        } catch (Exception e) {
            logger.error("查询投诉列表出错" +  e);
            return ReturnValue.generateFalseReturnValue("查询投诉列表出错");
        }
    }

    @ApiOperation(value="查询投诉详情")
    @GetMapping("/queryComplaints/{id}")
    public ReturnValue details(@PathVariable Integer id) {
        try {
            Complaints complaints=new Complaints();
            complaints=complaintsService.findById(id);
            return ReturnValue.generateTrueReturnValue(complaints);
        } catch (Exception e) {
            logger.error("查询投诉详情出错" +  e);
            return ReturnValue.generateFalseReturnValue("查询投诉详情出错");
        }
    }

    @ApiOperation(value="投诉执行")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "model", value = "投诉实体", dataType = "ComplaintsModel", paramType = "body"),
    })
    @PostMapping("/runComplaints")
    public ReturnValue add(@RequestBody ComplaintsModel model) {
        try {
           return complaintsService.runComplaint(model);
        } catch (Exception e) {
            logger.error("投诉执行出错" + model, e);
            return ReturnValue.generateFalseReturnValue("投诉执行出错");
        }
    }


}
